import store from './store'

export default {
	inserted(el, binding, vnode) {
		const { value } = binding
		const auths = store.getters && store.getters.auths
		if (value) {
			const permissionAuth = value
			const hasPermission = auths.some(auth => {
				return auth == permissionAuth
			})
			if (!hasPermission) {
				el.parentNode && el.parentNode.removeChild(el)
			}
		} else {
			throw new Error(`need roles! Like v-permission="['admin','editor']"`)
		}
	}
}
